﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Disk
{
    public partial class register : Form
    {
        public static login login = new login();
        public register()
        {
            InitializeComponent();
        }

        private void register_Load(object sender, EventArgs e)
        {
            //增加密保下拉选项//QuestionBox.Items.Add("你最喜欢的歌曲？");
            //加载时焦点在idbox
            IdBox.Focus();
        }
        //窗体关闭事件
        private void register_FormClosing(object sender, FormClosingEventArgs e)
        {
            /*if (MessageBox.Show("要退出程序吗？", "退出程序", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                //取消订阅事件
                this.FormClosing -= register_FormClosing;
               
            }
            else
            {
                e.Cancel = true;
            }*/
            Application.Exit();
        }
        //注册按钮点击事件
        private void Rebutton_Click(object sender, EventArgs e)
        {
            string username;
            string password;
            string secret;
            string answer;
            this.pictureBox2.Image = Properties.Resources.bili1;
            if (IdBox.Text != "")
            {
                if (PassBox.Text != "")
                {
                    if (RePassBox.Text!="")
                    {
                        if (RePassBox.Text == PassBox.Text)
                        {
                            if (QuestionBox.Text != ""  )
                            {
                                if (Answer.Text != "")
                                {
                                    username = IdBox.Text;
                                    password = PassBox.Text;
                                    secret = QuestionBox.Text;
                                    answer = Answer.Text;
                                   bool sulet= Upload.Register(username,password,secret,answer);
                                    if (sulet==true)
                                    {
                                        MessageBox.Show("注册成功，进入登录界面", "注册提示");
                                        //显示登录窗体，隐藏注册窗体
                                        login.Show();
                                        this.Hide();
                                    }
                                    else
                                    {
                                        IdBox.Focus();
                                        MessageBox.Show("注册失败，请重新注册", "注册提示");
                                    }
                                }
                                else if (Answer.Text == "")
                                {
                                    Answer.Focus();
                                    MessageBox.Show("请输入密保答案", "注册提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                            else if (QuestionBox.Text == "")
                            {
                                QuestionBox.Focus();
                                MessageBox.Show("请选择密保问题", "注册提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else if (RePassBox.Text != PassBox.Text)
                        {
                            RePassBox.Focus();
                            MessageBox.Show("请重新确认密码", "注册提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else if (RePassBox.Text == "")
                    {
                        RePassBox.Focus();
                        MessageBox.Show("请重新确认密码", "注册提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (PassBox.Text == "")
                {
                    PassBox.Focus();
                    MessageBox.Show("请输入密码", "注册提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (IdBox.Text == "")
            {
                IdBox.Focus();
                MessageBox.Show("请输入账号", "注册提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //点击密码框图片切换
        private void PassBox_Click(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }
        //点击确认密码框图片切换
        private void RePassBox_Click(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }
        //点击密保答案框图片切换
        private void Answer_Click(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }
        //点击账号答案框图片切换
        private void IdBox_Click(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili1;
        }
        //点击问题答案框图片切换
        private void QuestionBox_Click(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili1;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        { 
            //显示登录窗体，隐藏注册窗体
            login.Show();
            this.Hide();
        }

        private void IdBox_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili1;
        }

        private void PassBox_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }

        private void RePassBox_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }

        private void QuestionBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili1;
        }

        private void Answer_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }
    }
 }

